package cn.cxj.pet.service.impl;

import cn.cxj.basic.service.impl.BaseServiceImpl;
import cn.cxj.pet.domain.Pet;
import cn.cxj.pet.domain.PetDetail;
import cn.cxj.pet.mapper.PetDetailMapper;
import cn.cxj.pet.mapper.PetMapper;
import cn.cxj.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void onsale(Long[] ids) {
        petMapper.onsale(ids);
    }

    @Override
    public void offsale(Long[] ids) {
        petMapper.offSale(ids);
    }

    @Override
    public Pet loadByIdDetail(Long id) {
        return petMapper.loadByIdDetail(id);
    }

    @Override
    public void add(Pet pet) {
        // 设置宠物为上架状态
        pet.setState(1);
        // 新增宠物信息,返回自增id
        petMapper.save(pet);
        PetDetail detail = pet.getDetail();
        if (detail != null) {
            detail.setPet_id(pet.getId());
            // 新增宠物详情信息
            petDetailMapper.save(detail);
        }
    }
}
